#ifndef DATAMANIPULATOR_H
#define DATAMANIPULATOR_H

#include "datamanipulator_global.h"



#include <QPoint>
#include <QVector>
#include <QImage>
#include <QStack>
#include <QFont>
#include "..\SceneData\ContainerNode.h"
#include "..\SceneData\PathNode.h"
#include "..\SceneData\PictureNode.h"
#include "..\SceneData\SymbolNode.h"
#include "..\SceneData\RectNode.h"
#include "..\SceneData\MovieClipNode.h"
#include "..\SceneData\EclipseNode.h"
#include "..\SceneData\WordShapeNode.h"
#include "..\SceneData\Ease.h"
#include "..\SceneData\SceneNode.h"

enum propertyType {
		posx=1,
		posy=2,
		axisx=4,
		axisy=8,
		scalex=16,
		scaley=32,
		skewx=64,
		skewy=128,
		angle=256,
		alpha=512,
		visible=1024
	};

class DATAMANIPULATOR_EXPORT DataManipulator
{
public:
	DataManipulator();
	~DataManipulator();
	public:
	bool			IsOpened()const{return proj_opened;}
    void			CreateProject(QString name,int width=500,int height=300,QColor bkcolor=QColor(255,255,255),int fps=24);
    void			LoadProject(SceneNode* SceneData,MovieClipNode* SceneRoot);
	void			CloseProject();
	void			EnterIntoChild(int index);
	void			EscapeToParent();
	void			NewMovieClip(int index=-1);
    
	void			BeginDrawingAt(int index=-1);
	void			ConvertToPath(int index);
	void			ConvertToImage(int index);
	void			ConvertToMovieClip(int index);
	//void			EditAt(int index);
	void			AddRect(double width,double height,int index=-1);
	void			AddEclipse(double width,double height,int index=-1);
	void			AddPicture(QString path,int index=-1);
	void			AddPicture(QImage image,int index=-1);
	void			AddText(QString text,QFont font=QFont(),int index=-1);
	void			BeginPath(int index=-1);
	void			EndPath();
	void			AddLinearPoint(const QPointF& pt);
    void			AddSharpPoint(const QPointF& pt,const QPointF& cpt);
	void			AddSmoothPoint(const QPointF& pt,const QPointF& cpt);
	void			AddSymmetricalPoint(const QPointF& pt,const QPointF& cpt);
	void			ChangePointType(int index,ePtType type);
	const QPointF&	PointAt(int index);
	const QPointF&	LControlPointAt(int index);
	const QPointF&	RControlPointAt(int index);
	void			MovePointAt(int index , double x,double y);
	void			MoveLControlPointAt(int index , double x,double y);
	void			MoveRControlPointAt(int index , double x,double y);
	void			RemovePointAt(int index);
	int				PointIndexOf(double x,double y);
	void			ClosePath();
	ePtType			PointType(int index);

	
    void			RemoveNodeAt(int index);
	void			AddNodeAt(DisplayNode * ref,int index =-1 );
    void			ExchangeNodeAt(int index1,int index2);
	void			SetNodeProperty(propertyType pt,double value,int time=0,Ease::EaseType ease=Ease::ALLStart);
	double			GetNodeProperty(propertyType pt,int time=0);
	Ease::EaseType	GetNodePropertyEase(propertyType pt,int time=0);

	
	QVector<int > GetKeyFrames(int flags,int index=-1)const;
	void RemoveKeyFrames(int flags,int time,int index=-1);





    void			ToRoot();
	SceneNode*		ScenePt(){return scene;}
    const DisplayNode*	CurrentPt();
    const DisplayNode*	ChildPtAt(int index);
    const QImage&	CurrentImage();
    const QImage&	ChildImageAt(int index);
	QPen& CurrentPen();
	QBrush& CurrentBrush();

	void WordFont(const QFont& font);
	void WordText(const QString& text);




    int				ChildrenCount();
    eNodeType		CurrentNodeType();
    QString			CurrentNodeName()const{return  current->GetNodeName();}
	void			SetCurrentNodeName(QString name){current->SetNodeName(name);}
    eNodeType		ChildrenNodeType(int index);
	int	ChildUnderPointAt(QPointF pt);
	QVector<int>	ChildrenUnderPointAt(QPointF pt);
	int IndexOfChild(DisplayNode * child);
	int IndexOfCurrent();
	void Update();
private:
	SceneNode* scene;
	MovieClipNode *root;
	DisplayNode *current;
	QStack<DisplayNode *> enterHistory;
	bool proj_opened;
	void SetDirty();
};

#endif // DATAMANIPULATOR_H
